home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Qpopper / pop_msg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-06-06  |  2.6 KB  |  99 lines

  1. /*
  2.  * Copyright (c) 1989 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  9. static char SccsId[] = "@(#)@(#)pop_msg.c    2.1  2.1 3/18/91";
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #if defined(SOLARIS2) || defined(SYSV) || defined(AIX)
  15. #include <string.h>
  16. #else
  17. #include <strings.h>
  18. #endif
  19. #include <varargs.h>
  20. #include "popper.h"
  21.  
  22. /* 
  23.  *  msg:    Send a formatted line to the POP client
  24.  */
  25.  
  26. pop_msg(va_alist)
  27. va_dcl
  28. {
  29.     POP             *   p;
  30.     int                 stat;               /*  POP status indicator */
  31.     char            *   format;             /*  Format string for the message */
  32.     va_list             ap;
  33.     register char   *   mp;
  34. #ifdef PYRAMID
  35.     char        *   arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
  36. #endif
  37.     char                message[MAXLINELEN];
  38.  
  39.     va_start(ap);
  40.     p = va_arg(ap, POP *);
  41.     stat = va_arg(ap, int);
  42.     format = va_arg(ap, char *);
  43. #ifdef PYRAMID
  44.     arg1 = va_arg(ap, char *);
  45.     arg2 = va_arg(ap, char *);
  46.     arg3 = va_arg(ap, char *);
  47.     arg4 = va_arg(ap, char *);
  48.     arg5 = va_arg(ap, char *);
  49.     arg6 = va_arg(ap, char *);
  50. #endif
  51.  
  52.     /*  Point to the message buffer */
  53.     mp = message;
  54.  
  55.     /*  Format the POP status code at the beginning of the message */
  56.     if (stat == POP_SUCCESS)
  57.         (void)sprintf (mp,"%s ",POP_OK);
  58.     else
  59.         (void)sprintf (mp,"%s ",POP_ERR);
  60.  
  61.     /*  Point past the POP status indicator in the message message */
  62.     mp += strlen(mp);
  63.  
  64.     /*  Append the message (formatted, if necessary) */
  65.     if (format) 
  66. #ifdef HAVE_VSPRINTF
  67.         vsprintf(mp,format,ap);
  68. #else
  69. # ifdef PYRAMID
  70.         (void)sprintf(mp,format, arg1, arg2, arg3, arg4, arg5, arg6);
  71. # else
  72.         (void)sprintf(mp,format,((int *)ap)[0],((int *)ap)[1],((int *)ap)[2],
  73.                 ((int *)ap)[3],((int *)ap)[4]);
  74. # endif
  75. #endif
  76.     va_end(ap);
  77.     
  78.     /*  Log the message if debugging is turned on */
  79. #ifdef DEBUG
  80.     if (p->debug && stat == POP_SUCCESS)
  81.         pop_log(p,POP_DEBUG,"%s",message);
  82. #endif
  83.  
  84.     /*  Log the message if a failure occurred */
  85.     if (stat != POP_SUCCESS) 
  86.     pop_log(p,POP_PRIORITY,
  87.                (isdigit (p->client[0]) ? "%s@[%s]: %s" : "%s@%s: %s"),
  88.                (p->user ? p->user : "(null)"), p->client, message);
  89.  
  90.     /*  Append the <CR><LF> */
  91.     (void)strcat(message, "\r\n");
  92.         
  93.     /*  Send the message to the client */
  94.     (void)fputs(message,p->output);
  95.     (void)fflush(p->output);
  96.  
  97.     return(stat);
  98. }
  99.